package com.spic.business.informatization.accounting.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.business.informatization.accounting.domain.MeetingAccounting;
import com.spic.business.informatization.accounting.service.IMeetingAccountingService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
;

/**
 * 班前班后会Controller
 *
 * @author spic
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/informatization/accounting")
public class MeetingAccountingController extends BaseController
{
    @Autowired
    private IMeetingAccountingService meetingAccountingService;

    /**
     * 查询班前班后会列表
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:list")
    @GetMapping("/list")
    public TableDataInfo list(MeetingAccounting meetingAccounting)
    {
        startPage();
        List<MeetingAccounting> list = meetingAccountingService.selectMeetingAccountingList(meetingAccounting);
        return getDataTable(list);
    }

    /**
     * 导出班前班后会列表
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:export")
    @Log(title = "班前班后会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingAccounting meetingAccounting) throws IOException
    {
        List<MeetingAccounting> list = meetingAccountingService.selectMeetingAccountingList(meetingAccounting);
        ExcelUtil<MeetingAccounting> util = new ExcelUtil<MeetingAccounting>(MeetingAccounting.class);
        util.exportExcel(response, list, "班前班后会数据");
    }

    /**
     * 获取班前班后会详细信息
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(meetingAccountingService.selectMeetingAccountingById(id));
    }

    /**
     * 新增班前班后会
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:add")
    @Log(title = "班前班后会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingAccounting meetingAccounting)
    {
        return toAjax(meetingAccountingService.insertMeetingAccounting(meetingAccounting));
    }

    /**
     * 修改班前班后会
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:edit")
    @Log(title = "班前班后会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingAccounting meetingAccounting)
    {
        return toAjax(meetingAccountingService.updateMeetingAccounting(meetingAccounting));
    }

    /**
     * 删除班前班后会
     */
    @PreAuthorize(hasPermi = "business/informatization:accounting:remove")
    @Log(title = "班前班后会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingAccountingService.deleteMeetingAccountingByIds(ids));
    }
    /**
     * 生成班前班后会关联工作单
     */
    @PutMapping(value = "generate_ticket/{id}")
    public AjaxResult generateTicket(@PathVariable("id") Long id)
    {
        meetingAccountingService.generateTicket(id);
        return AjaxResult.success();
    }
}
